<?php
include_once("sessionmanager.php");
initSession();

if (!isset($_SESSION['s_loggedin']) || ($_SESSION['s_loggedin'] == false) || !isset($_SESSION['s_serverurl']) || (strpos($_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'],$_SESSION['s_serverurl']) === false)) {
	$error_page_code = "timeout";
	include "errorpage.php";
	exit();
}
if (!$_SESSION['s_statusview']) {
	$error_page_code = "permission";
	include "errorpage.php";
	exit();
}

include "languages.php";
include_once "functions.inc.php";
include "attributes.php";
$userid = $_SESSION['s_userid'];

makeheader(STATUS_TITLE);

$page = (isset($_GET['page']) && is_numeric($_GET['page'])) ? (int)$_GET['page'] : 1;
?>
<table cellpadding="1" cellspacing="0" border="0" align="center" width="90%" class="tblborder"><tr><td>
<table cellpadding="4" cellspacing="0" border="0" width="100%">
<?php
include ("config.php");
mysql_connect($dbhost,$dbusername,$dbpassword) or die(PARSER_ERROR3);
mysql_select_db($dbname) or die(PARSER_ERROR2);

// maximale Galaxienummer bestimmen
$query = "SELECT MAX(galaxie) as maxgala FROM $dbtablename where userid=$userid";
$res = mysql_query($query) or die(mysql_error());
$line = mysql_fetch_object($res);
$maxgala = $line->maxgala;


// Tabelle aufstellen
for ($j=1;$j<500;$j++) {
	$galaxiearray[$j] = 0; // Datumstempel auf 0 setzen
	$userarray[$j] = "unknown";
}

$query = "SELECT g.system,g.zeit,u.username FROM $dbtablename g LEFT JOIN $utablename u ON (g.userid=u.id) WHERE g.userid=$userid AND g.galaxie='$page' AND g.planet='1'";
$res   = mysql_query($query) or die(mysql_error());
while ($line = mysql_fetch_object($res)) {
	$galaxiearray[$line->system] = $line->zeit;
	$userarray[$line->system] = date("d.m.Y",$line->zeit);
}

echo "<tr class=\"firstcolor\"><td colspan=\"2\" class=\"tblhead\">".USER_GALAXY.": \n";
draw_pagenumbers($page,$maxgala,1,$_SERVER['PHP_SELF'],"page");
echo "</td></tr>\n";
$tablestring = "<table width=\"99%\" align=\"center\">";

for ($j=1;$j<=50;$j++) {
	$tablestring .= "<tr>\n";
	for ($i=0;$i<10;$i++) {
		if ($j+$i*50 == 500) {
			$tablestring .= "<td width=\"11%\">&nbsp;</td>\n";
			break;
		}
		$title = $userarray[$j+$i*50];
		if ($galaxiearray[$j+$i*50] == 0) $tablestring .= "<td class=\"farbe7\" width=\"11%\" onmouseover='this.T_WIDTH=150;return escape(\"$title\")'><del>$page:".($j+$i*50)."</del></td>\n";     // noch kein Eintrag
		elseif ($galaxiearray[$j+$i*50] < (time() - 86400*30)) $tablestring .= "<td width=\"11%\"><a onmouseover='this.T_WIDTH=150;return escape(\"$title\")' class=\"farbe6\" href=\"view.php?gala=$page&amp;system=".($j+$i*50)."\">$page:".($j+$i*50)."</a></td>\n"; // 1 Monat und mehr
		elseif ($galaxiearray[$j+$i*50] < (time() - 86400*14)) $tablestring .= "<td width=\"11%\"><a onmouseover='this.T_WIDTH=150;return escape(\"$title\")' class=\"farbe5\" href=\"view.php?gala=$page&amp;system=".($j+$i*50)."\">$page:".($j+$i*50)."</a></td>\n"; // 2-4 Wochen
		elseif ($galaxiearray[$j+$i*50] < (time() - 86400*7)) $tablestring .= "<td width=\"11%\"><a onmouseover='this.T_WIDTH=150;return escape(\"$title\")' class=\"farbe4\" href=\"view.php?gala=$page&amp;system=".($j+$i*50)."\">$page:".($j+$i*50)."</a></td>\n"; // 1-2 Wochen
		elseif ($galaxiearray[$j+$i*50] < (time() - 86400*4)) $tablestring .= "<td width=\"11%\"><a onmouseover='this.T_WIDTH=150;return escape(\"$title\")' class=\"farbe3\" href=\"view.php?gala=$page&amp;system=".($j+$i*50)."\">$page:".($j+$i*50)."</a></td>\n"; // 4-7 Tage
		elseif ($galaxiearray[$j+$i*50] < (time() - 86400*2)) $tablestring .= "<td width=\"11%\"><a onmouseover='this.T_WIDTH=150;return escape(\"$title\")' class=\"farbe2\" href=\"view.php?gala=$page&amp;system=".($j+$i*50)."\">$page:".($j+$i*50)."</a></td>\n"; // 2-4 Tage
		else $tablestring .= "<td width=\"11%\"><a onmouseover='this.T_WIDTH=150;return escape(\"$title\")' class=\"farbe1\" href=\"view.php?gala=$page&amp;system=".($j+$i*50)."\">$page:".($j+$i*50)."</a></td>\n";
	}
	$tablestring .= "</tr>\n";
}
$tablestring .="</table>\n";
echo "<tr><td colspan=\"2\" class=\"firstcolor\" width=\"100%\">$tablestring</td></tr>";
?>
<tr class="tblhead"><td colspan="2"><?php echo STATUS_DB_STATUS; ?></td></tr>
<tr class="firstcolor"><td class="farbe1"><?php echo STATUS_COLOR; ?>1</td>

<td><?php echo STATUS_AGE1; ?></td>
</tr>
<tr class="firstcolor"><td class="farbe2"><?php echo STATUS_COLOR; ?>2</td>
<td><?php echo STATUS_AGE2; ?></td>
</tr>
<tr class="firstcolor"><td class="farbe3"><?php echo STATUS_COLOR; ?>3</td>
<td><?php echo STATUS_AGE3; ?></td>
</tr>
<tr class="firstcolor"><td class="farbe4"><?php echo STATUS_COLOR; ?>4</td>
<td><?php echo STATUS_AGE4; ?></td>

</tr>
<tr class="firstcolor"><td class="farbe5"><?php echo STATUS_COLOR; ?>5</td>
<td><?php echo STATUS_AGE5; ?></td>
</tr>
<tr class="firstcolor"><td class="farbe6"><?php echo STATUS_COLOR; ?>6</td>
<td><?php echo STATUS_AGE6; ?></td>
</tr>
<tr class="firstcolor"><td class="farbe7"><?php echo STATUS_COLOR; ?><del>7</del></td>
<td><?php echo STATUS_AGE7; ?></td>
</tr>

<?
echo "</table></td></tr></table>";



makefooter();
?>
